package utils

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type Response struct {
	Code    int         `json:"code"`    // 状态码：0成功，非0失败
	Message string      `json:"message"` // 响应消息
	Data    interface{} `json:"data"`    // 响应数据，可为nil
}

func Success(c *gin.Context,data interface{}){
	c.JSON(http.StatusOK,Response{
		Code: 0,
		Message: "success",
		Data: data,
	})
}
func Failed(c *gin.Context,message string){
	c.JSON(http.StatusBadRequest,Response{
		Code:    500,
		Message: message,
		Data:    nil,
	})
}

// Unauthorized 未授权响应
func Unauthorized(c *gin.Context,message string){
	c.JSON(http.StatusUnauthorized, Response{
		Code:    401,
		Message: message,
		Data:    nil,
	})
}